/*
 * 接收服務器公共事件廣播
 */ 
function internalEvent() {
	if ( internalEvent.prototype.handleFun == undefined ) {
		internalEvent.prototype.handleFun = function(evtObj) {
			var _fun_name = evtObj.name;
			this[_fun_name](evtObj);
		}
	}
	/**
	 * 登入請求事件(自定義登入)
	 * 
	 * @param	evtObj	{nick:用戶名，pass:用戶密碼，chan:用戶渠道}
	 */
	if ( internalEvent.prototype.loginRequest == undefined ) {
		internalEvent.prototype.loginRequest = function(evtObj) {						
			var _id   = evtObj.nick;			
			var _key  = evtObj.pass;
			var _chan = evtObj.chan;
			var _res  = login(_id, _key, _chan);
			if (_res) {		
				var _user = _server.getUserByChannel(_chan);				
				_server.sendResponse(_res, -1, null, _chan, 'json');				
				__friendsEvent.getFriends(_user);
				//_server.sendRoomList(_server.getUserByChannel(_chan));
			}else {
				var _param = { };
				_param._cmd = 'loginFaild';
				_param.dataObj = { err:8002 };
				_server.sendResponse(_param, -1, null, _chan, 'json');				
			}			
			return;			
		}
	}
	/*
	 *登入房間事件 
	 */
	if ( internalEvent.prototype.userJoin == undefined ) {
		internalEvent.prototype.userJoin = function(evtObj) {
			var r = evtObj.room;
			var u = evtObj.user;			
		}
	}
	/*
	 *登出事件 ,保存記錄入數據庫
	 */
	if ( internalEvent.prototype.userLost == undefined ) {
		internalEvent.prototype.userLost = function(evtObj) {
			var u = evtObj.user;						
			__userEvent.exchangeGold(u);	//将数据库中筹码转回玩家点数		
			//清空座位
			if ( !u.isSpectator() ) {
				var rid = u.getRoom();
				var r = _zone.getRoom(rid);
				if (r == null || u == null) {					
					return;
				}
				_roomAc.standUp(r, u, { } );
			}		
			__debug.trace("User: " + u.getName() + " Lost ");			
		}
	}
	/*
	 *退出房間事件 
	 */
	if ( internalEvent.prototype.userExit == undefined ) {
		internalEvent.prototype.userExit = function(evtObj) {
			var r = evtObj.room;
			var u = evtObj.user;
			var uid = evtObj.uid;			
			__debug.trace("userId: "+u.getName()+" exit  roomId :"+r.getId());
		}
	}
	/**
	 * 服務器啟動
	 */
	if ( internalEvent.prototype.serverReady == undefined ) {
		internalEvent.prototype.serverReady = function(evtObj) {			
			__debug.trace("Texas server is running");
		}
	}
	/**
	 * 房間銷毀
	 */
	if ( internalEvent.prototype.roomLost == undefined ) {
		internalEvent.prototype.roomLost = function(evtObj) {
			//trace("A room has lost");			
		}
	}	
	/**
	 * 玩家從遊戲者變為觀看者
	 */
	this.playerSwitched = function(evt) {
		var u = evt.user;		
	}
	/**
	 * 玩家從觀看者變為遊戲者
	 */
	this.spectatorSwitched = function(evt) {
		var u = evt.user;
	}
	this.logOut = function(evt) {
		trace("logOUt");
	}
}
